From cdbaa7493e29a9167766f4d6129a5042a6cabcf3 Mon Sep 17 00:00:00 2001 From: Seth Falcon Date: Fri, 3 Jul 2015 15:36:25 -0700 Subject: [PATCH] Disallow nesting of packages with same packge_id If a package contains a subdirectory that contains a copy of itself (strange, but encountered in the wild in the context of an OS package build tool), cargo was failing with a non-descriptive "An unknown error occurred" (or "no package found in source" with --verbose). Since nested packages use the root path, such a package will have an identical package_id to the root package. With this patch, we keep the first occurance of a given package_id rather than overwritting -- effectively ignoring the nested package with duplicated name. A warn! message is printed. --- src/cargo/ops/cargo_read_manifest.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 850785326..3711d263e 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -112,7 +112,13 @@ fn read_nested_packages(path: &Path, let manifest = try!(find_project_manifest_exact(path, "Cargo.toml")); let (pkg, nested) = try!(read_package(&manifest, source_id, config)); - all_packages.insert(pkg.package_id().clone(), pkg); + let pkg_id = pkg.package_id().clone(); + if !all_packages.contains_key(&pkg_id) { + all_packages.insert(pkg_id, pkg); + } else { + warn!("skipping nested package `{}` found at `{}`", + &pkg.name(), &path.to_string_lossy()); + } // Registry sources are not allowed to have `path=` dependencies because // they're all translated to actual registry dependencies. -- 2.30.2